﻿/*版权声明
 * 
 * 本 WebName:IMIS_ERP 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者
 * 负责人：朱胜贤
 * 成员：水亚亚、孙旭峰、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 *
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 *
 * CopyRight (c) 河北大学信管团队 2010~2020
 */

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using IMIS_ERP.DBUtility;//Please add references
namespace IMIS_ERP.DAL
{
    /// <summary>数据访问类:Manager_Role
    ///     <remarks>2011-03-07 河北大学信管团队</remarks>
    /// </summary>
    public class Manager_Role
    {
        public Manager_Role()
        { }
        #region  Method

        /// <summary>是否存在该记录
        ///     <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="mrName">编号</param>
        /// <returns>返回是否存在</returns>
        public bool Exists(string mrName)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@mrName", SqlDbType.NVarChar,50)};
            parameters[0].Value = mrName;

            int result = DbHelperSQL.RunProcedure("UP_Manager_Role_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>增加一条数据
        ///      <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否添加成功</returns>
        public bool Add(IMIS_ERP.Model.Manager_Role model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@mrName", SqlDbType.NVarChar,10),
					new SqlParameter("@mrType", SqlDbType.NChar,1),
					new SqlParameter("@mrProvince", SqlDbType.NVarChar,20),
					new SqlParameter("@mrCity", SqlDbType.NVarChar,50),
					new SqlParameter("@mrCode", SqlDbType.NVarChar,50),
					new SqlParameter("@mrRemark", SqlDbType.NText)};
            parameters[0].Value = model.mrName;
            parameters[1].Value = model.mrType;
            parameters[2].Value = model.mrProvince;
            parameters[3].Value = model.mrCity;
            parameters[4].Value = model.mrCode;
            parameters[5].Value = model.mrRemark;

            return DbHelperSQL.GetIsRunOK("UP_Manager_Role_ADD", parameters);
        }

        /// <summary>更新一条数据
        ///      <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否修改成功</returns>
        public bool Update(IMIS_ERP.Model.Manager_Role model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@mrName", SqlDbType.NVarChar,10),
					new SqlParameter("@mrType", SqlDbType.NChar,1),
					new SqlParameter("@mrProvince", SqlDbType.NVarChar,20),
					new SqlParameter("@mrCity", SqlDbType.NVarChar,50),
					new SqlParameter("@mrCode", SqlDbType.NVarChar,50),
					new SqlParameter("@mrRemark", SqlDbType.NText)};
            parameters[0].Value = model.mrName;
            parameters[1].Value = model.mrType;
            parameters[2].Value = model.mrProvince;
            parameters[3].Value = model.mrCity;
            parameters[4].Value = model.mrCode;
            parameters[5].Value = model.mrRemark;

            return DbHelperSQL.GetIsRunOK("UP_Manager_Role_Update", parameters);
        }

        /// <summary>删除一条数据
        ///      <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="mrName">编号</param>
        /// <returns>返回是否删除成功</returns>
        public bool Delete(string mrName)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@mrName", SqlDbType.NVarChar,50)};
            parameters[0].Value = mrName;

            return DbHelperSQL.GetIsRunOK("UP_Manager_Role_Delete", parameters);
        }

        /// <summary>批量删除记录
        ///      <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="mrNamelist">编号</param>
        /// <returns>返回删除的记录条数</returns>
        public int DeleteList(string mrNamelist)
        {
            int i = 0;
            try
            {
                string[] mrName = mrNamelist.Split(',');
                foreach (string str in mrName)
                {
                    if (Delete(str))
                    {
                        i++;
                    }
                }
                return i;
            }
            catch
            {
                return i;
            }
        }

        /// <summary>得到一个对象实体
        ///      <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="mrName">编号</param>
        /// <returns>返回Model</returns>
        public IMIS_ERP.Model.Manager_Role GetModel(string mrName)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@mrName", SqlDbType.NVarChar,50)};
            parameters[0].Value = mrName;

            IMIS_ERP.Model.Manager_Role model = new IMIS_ERP.Model.Manager_Role();
            DataSet ds = DbHelperSQL.RunProcedure("UP_Manager_Role_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.mrName = ds.Tables[0].Rows[0]["mrName"].ToString();
                model.mrType = ds.Tables[0].Rows[0]["mrType"].ToString();
                model.mrProvince = ds.Tables[0].Rows[0]["mrProvince"].ToString();
                model.mrCity = ds.Tables[0].Rows[0]["mrCity"].ToString();
                model.mrCode = ds.Tables[0].Rows[0]["mrCode"].ToString();
                model.mrRemark = ds.Tables[0].Rows[0]["mrRemark"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>获得数据列表
        ///     <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <returns>返回DataSet</returns>
        public SqlDataReader GetList()
        {
            return DbHelperSQL.RunProcedure("UP_Manager_Role_GetList");
        }

        /// <summary>获得前几行数据
        ///     <remarks>2011-03-07 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="Top">行数</param>
        /// <param name="strWhere">条件</param>
        /// <param name="filedOrder">排序</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" mrName,mrType,mrProvince,mrCity,mrCode,mrRemark ");
            strSql.Append(" FROM Manager_Role ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

